
import os
import config
from PyQt4 import QtCore, QtGui


def resouce(filepath):
    return os.path.join(config.RESOURCE_PATH, filepath)


def image(filename):
    return os.path.join(config.RESOURCE_IMAGES_PATH, filename)


def qstring_to_string(qstring):
    return unicode(qstring.toUtf8(), 'utf-8', 'ignore')


def _from_utf8(string):
    try:
        string = str(string)
        return QtCore.QString.fromUtf8(string)
    except AttributeError:
        return string

try:
    _encoding = QtGui.QApplication.UnicodeUTF8


    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)